package com.zjj.lbw.microservice.nacos.provider.nacosprovider;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@EnableScheduling
public class NacosProviderApplication {

    public static void main(String[] args) throws InterruptedException {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(NacosProviderApplication.class, args);

        System.out.println(applicationContext.getBean("testController"));

        while (true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔3秒中从Enviroment中获取配置
            String userName = applicationContext.getEnvironment().getProperty("user.name");
            String userAge = applicationContext.getEnvironment().getProperty("user.age");
            System.out.println("user name:" + userName + "; age: " + userAge);
            String commonName = applicationContext.getEnvironment().getProperty("common.name");
            System.out.println("common name: " + commonName);
            TimeUnit.SECONDS.sleep(3);

        }

    }
}
